﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLBH.DTO;
using Module.Category.BL;
using QLBH.DataModel;
using QLBH.Model.Controller;

namespace Module.Category
{
    public partial class AddCalUnitDlg : Form
    {
        private DVTDTO calUnit;

        public DVTDTO CalUnit
        {
            get { return calUnit; }
            
        }
        public AddCalUnitDlg()
        {
            InitializeComponent();

            calUnit = new DVTDTO();
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBoxName.Text))
            {
                MessageBox.Show("Bạn phải nhập tên Đơn Vị", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            calUnit.GhiChu = textBoxComment.Text;
            calUnit.TenDV = textBoxName.Text;

            AddCalUnit();

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
        /// <summary>
        /// Add New Calculate Unit
        /// </summary>
        /// <param name="newCalUnit"></param>
        /// <returns></returns>
        public void AddCalUnit()
        {
            try
            {
                DVT newCalUnit = DVTAssembler.ToEntity(calUnit);
                calUnit = CalculateUnitController.Instance.Add(newCalUnit).ToDTO();
                
            }
            catch (System.Exception ex)
            {
                throw ex;
            }

        }
        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
